package com.etone.smartAudit.utils;

import com.alibaba.excel.util.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: sovy
 * @date: 2019/6/1
 * @description:
 */
public class StringUtil {
    /**
     * 首字母大写
     */
    public static String upperFistChar(String str) {
        char[] ch = str.toCharArray();
        if (ch[0] >= 'a' && ch[0] <= 'z') {
            ch[0] = (char) (ch[0] - 32);
        }
        return new String(ch);
    }

    /**
     * 首字母小写
     */
    public static String lowerFistChar(String str) {
        char[] ch = str.toCharArray();
        if (ch[0] >= 'A' && ch[0] <= 'Z') {
            ch[0] = (char) (ch[0] + 32);
        }
        return new String(ch);
    }

    /**
     * String strInt 转 List<Integer>
     * @param strInt
     * @return
     */
    public static List<Integer> intToList(String strInt){
        if (StringUtils.isNotBlank(strInt)){
            String[] split = strInt.split(",");
            List<Integer> list = new ArrayList<>();
            for (String id : split) {
                list.add(Integer.valueOf(id));
            }
            return list;
        }
        return Collections.emptyList();
    }

    /**
     * String str 转 List<String>
     * @param str
     * @return
     */
    public static List<String> stringToList(String str){
        if (StringUtils.isNotBlank(str)){
            String[] split = str.split(",");
            List<String> collect =  Arrays.stream(split).collect(Collectors.toList());
            return collect;
        }
        return Collections.emptyList();
    }

}
